package com.settlement.system.model.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.settlement.system.common.base.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 天猫平台订单
 * </p>
 *
 * @author huangrensen
 * @since 2024-05-05
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class SysTmOrder extends BaseEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * ID
     */
    private String id;


    /**
     * 子订单编号
     */
    private String sourcePreformSubNo;


    /**
     * 主订单编号
     */
    private String sourcePreformMainNo;


    /**
     * 标题
     */
    private String title;


    /**
     * 价格
     */
    private BigDecimal price;


    /**
     * 购买数量
     */
    private Integer qty;


    /**
     * 外部系统编号
     */
    private String systemNo;


    /**
     * 商品属性
     */
    private String productInfo;


    /**
     * 套餐信息
     */
    private String pack;


    /**
     * 联系方式备注
     */
    private String remark;


    /**
     * 订单状态
     */
    private String status;


    /**
     * 商家编码
     */
    private String sellerCode;


    /**
     * 支付单号
     */
    private String payNo;


    /**
     * 买家应付货款
     */
    private BigDecimal totalAmount;


    /**
     * 买家实际支付金额
     */
    private BigDecimal actTotalAmount;


    /**
     * 退款状态
     */
    private String returnStatus;


    /**
     * 退款金额
     */
    private String returnAmount;


    /**
     * 订单创建时间
     */
    private LocalDateTime orderCreateTime;


    /**
     * 订单付款时间
     */
    private LocalDateTime orderPayTime;


    /**
     * 商品id
     */
    private String productId;


    /**
     * 分阶段订单信息
     */
    private String partInfo;


    /**
     * 备注标签
     */
    private String remarkTag;


    /**
     * 商家备注
     */
    private String sellerRemark;


    /**
     * 主订单买家留言
     */
    private String buyerRemark;


    /**
     * 发货时间
     */
    private LocalDateTime sendTime;


    /**
     * 物流单号
     */
    private String transportNo;


    /**
     * 物流公司
     */
    private String transportCompany;


    /**
     * 是否赔付
     */
    private String indemnity;


    /**
     * 赔付金额
     */
    private String indemnityAmount;


    /**
     * 赔付出账时间
     */
    private String indemnityBillTime;

    @TableField(exist = false)
    private String tableName;

    @TableField(exist = false)
    private List<String> sourcePreformSubNoList;

    private static boolean compareDate(LocalDateTime date1, LocalDateTime date2) {
        if (date1 == null && date2 == null) {
            return true;
        }
        if (date1 != null && date2 == null) {
            return false;
        }
        return date1 != null && date1.equals(date2);
    }

    private static boolean compareBigDecimal(BigDecimal value1, BigDecimal value2) {
        if (value1 == null && value2 == null) {
            return true;
        }
        if (Objects.isNull(value2)) {
            value2 = BigDecimal.ZERO;
        }
        return value1 != null && value1.compareTo(value2) == 0;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        if (!super.equals(o)) return false;
        SysTmOrder that = (SysTmOrder) o;
        return Objects.equals(sourcePreformSubNo, that.sourcePreformSubNo) && Objects.equals(sourcePreformMainNo, that.sourcePreformMainNo) && Objects.equals(title, that.title) && Objects.equals(price, that.price) && Objects.equals(qty, that.qty) && Objects.equals(systemNo, that.systemNo) && Objects.equals(productInfo, that.productInfo) && Objects.equals(pack, that.pack) && Objects.equals(remark, that.remark) && Objects.equals(status, that.status) && Objects.equals(sellerCode, that.sellerCode) && Objects.equals(payNo, that.payNo) && compareBigDecimal(totalAmount, that.totalAmount) && compareBigDecimal(actTotalAmount, that.actTotalAmount) && Objects.equals(returnStatus, that.returnStatus) && Objects.equals(returnAmount, that.returnAmount) && compareDate(orderCreateTime, that.orderCreateTime) && compareDate(orderPayTime, that.orderPayTime) && Objects.equals(productId, that.productId) && Objects.equals(partInfo, that.partInfo) && Objects.equals(remarkTag, that.remarkTag) && Objects.equals(sellerRemark, that.sellerRemark) && Objects.equals(buyerRemark, that.buyerRemark) && compareDate(sendTime, that.sendTime) && Objects.equals(transportNo, that.transportNo) && Objects.equals(transportCompany, that.transportCompany) && Objects.equals(indemnity, that.indemnity) && Objects.equals(indemnityAmount, that.indemnityAmount) && Objects.equals(indemnityBillTime, that.indemnityBillTime);
    }

    @Override
    public int hashCode() {
        return Objects.hash(super.hashCode(), sourcePreformSubNo, sourcePreformMainNo, title, price, qty, systemNo, productInfo, pack, remark, status, sellerCode, payNo, totalAmount, actTotalAmount, returnStatus, returnAmount, orderCreateTime, orderPayTime, productId, partInfo, remarkTag, sellerRemark, buyerRemark, sendTime, transportNo, transportCompany, indemnity, indemnityAmount, indemnityBillTime);
    }
}
